<template>
  <div class="resources-container">
    <!-- 资源列表 -->
    <div class="resources-grid">
      <div 
        v-for="resource in resources" 
        :key="resource.id"
        class="resource-card"
      >
        <div class="resource-cover">
          <img :src="resource.cover" :alt="resource.title">
          <div class="resource-type">{{ resource.type }}</div>
        </div>

        <div class="resource-content">
          <h3 class="resource-title">{{ resource.title }}</h3>
          <p class="resource-desc">{{ resource.description }}</p>
          
          <div class="resource-meta">
            <div class="author">
              <el-avatar :src="resource.author.avatar" :size="24"></el-avatar>
              <span>{{ resource.author.name }}</span>
            </div>
            <div class="stats">
              <span class="downloads">
                <i class="fas fa-download"></i>
                {{ resource.downloads }}
              </span>
              <span class="likes">
                <i class="fas fa-heart"></i>
                {{ resource.likes }}
              </span>
            </div>
          </div>

          <div class="resource-tags">
            <span 
              v-for="tag in resource.tags" 
              :key="tag"
              class="tag"
            >#{{ tag }}</span>
          </div>
        </div>

        <div class="resource-footer">
          <div class="price" :class="{ 'free': resource.price === 0 }">
            {{ resource.price === 0 ? '免费' : `￥${resource.price}` }}
          </div>
          <button class="download-btn" @click="downloadResource(resource)">
            <i class="fas fa-download"></i>
            下载资源
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Resources',
  
  data() {
    return {
      resources: [
        {
          id: 1,
          title: 'Vue3完整项目模板',
          description: '包含Vue3、TypeScript、Vite、Element Plus的完整项目模板，开箱即用。',
          cover: 'https://picsum.photos/400/200?random=1',
          type: '项目模板',
          author: {
            name: '张三',
            avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=dev1'
          },
          downloads: 1234,
          likes: 567,
          tags: ['Vue3', 'TypeScript', 'Vite'],
          price: 0
        },
        {
          id: 2,
          title: 'API接口文档生成器',
          description: '自动从代码注释生成API文档，支持多种格式导出。',
          cover: 'https://picsum.photos/400/200?random=2',
          type: '开发工具',
          author: {
            name: '李四',
            avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=dev2'
          },
          downloads: 856,
          likes: 234,
          tags: ['API', '文档', '工具'],
          price: 29
        },
        {
          id: 3,
          title: 'React Native UI组件库',
          description: '高质量的React Native UI组件库，包含50+常用组件。',
          cover: 'https://picsum.photos/400/200?random=3',
          type: '组件库',
          author: {
            name: '王五',
            avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=dev3'
          },
          downloads: 567,
          likes: 123,
          tags: ['React Native', 'UI', '移动端'],
          price: 99
        }
      ]
    }
  },

  methods: {
    downloadResource(resource) {
      console.log('下载资源:', resource.id);
    }
  }
}
</script>

<style scoped>
.resources-container {
  padding: 2rem;
}

.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 2rem;
}

.resource-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.resource-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.resource-cover {
  position: relative;
  height: 200px;
  overflow: hidden;
}

.resource-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.resource-card:hover .resource-cover img {
  transform: scale(1.1);
}

.resource-type {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.25rem 0.75rem;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border-radius: 20px;
  font-size: 0.9rem;
}

.resource-content {
  padding: 1.5rem;
}

.resource-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #1a237e;
  margin-bottom: 0.75rem;
}

.resource-desc {
  color: #666;
  line-height: 1.6;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.resource-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.author {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #666;
}

.stats {
  display: flex;
  gap: 1rem;
  color: #666;
  font-size: 0.9rem;
}

.resource-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tag {
  padding: 0.25rem 0.75rem;
  background: #f0f2f5;
  color: #666;
  border-radius: 20px;
  font-size: 0.9rem;
}

.resource-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: #f8f9fa;
  border-top: 1px solid #eee;
}

.price {
  font-size: 1.2rem;
  font-weight: 600;
  color: #f44336;
}

.price.free {
  color: #4caf50;
}

.download-btn {
  padding: 0.5rem 1.5rem;
  background: #1a237e;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.download-btn:hover {
  background: #0d47a1;
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .resources-container {
    padding: 1rem;
  }

  .resources-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}
</style> 